//
//  timer.hpp
//  utilities
//
//  Created by Sam Jaffe on 4/28/13.
//  Copyright (c) 2013 Sam Jaffe. All rights reserved.
//

#pragma once

#include <tuple>
#include <functional>
#include <ctime>
#include <chrono>

template <class Ret, class ...Args>
std::tuple<std::time_t, Ret> timer(std::function<Ret(Args...)> f, Args&&... args) {
    using std::chrono::steady_clock;
    using std::chrono::microseconds;
    using std::chrono::duration_cast;
    steady_clock::time_point start = steady_clock::now();
    Ret temp = f(args...);
    steady_clock::time_point end = steady_clock::now();
    return std::make_tuple(duration_cast<microseconds>(end-start).count(), temp);
}

template <class ...Args>
std::tuple<std::time_t> timer(std::function<void(Args...)> f, Args&&... args) {
    using std::chrono::steady_clock;
    using std::chrono::microseconds;
    using std::chrono::duration_cast;
    steady_clock::time_point start = steady_clock::now();
    f(args...);
    steady_clock::time_point end = steady_clock::now();
    return std::make_tuple(duration_cast<microseconds>(end-start).count());
}
